﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class FlyTextPanelMgr
{
    private static List<FlyTextPanel> panels = new List<FlyTextPanel>();
    private static int MAX_COUNT = 10;

    public static void Show(string text)
    {
        FlyTextPanel flyTextPanel = Get();
        flyTextPanel.Show(text);
    }

    public static void Recycle(FlyTextPanel panel)
    {
        panels.Add(panel);
        int tempCount = panels.Count - MAX_COUNT;
        if (tempCount <= 0)
        {
            return;
        }

        for (int i=panels.Count-1; i>=0; i--)
        {
            FlyTextPanel flyTextPanel = panels[i];
            panels.RemoveAt(i);
            flyTextPanel.Dispose();
            tempCount--;
            if (tempCount <= 0)
            {
                break;
            }
        }
    }

    public static FlyTextPanel Get()
    {
        if (panels.Count > 0)
        {
            FlyTextPanel panel = panels[panels.Count - 1];
            panels.RemoveAt(panels.Count - 1);
            return panel;
        }

        FlyTextPanel flyTextPanel = new FlyTextPanel();
        flyTextPanel.Init();
        return flyTextPanel;
    }
}
